<template>
  <div>
    <!-- 生产信息登记 -->
      <el-col :xs="24" :sm="24" :md="12" :lg="24">
        <el-card class="update-log" style="margin-top: 20px">
          <div slot="header" class="clearfix">
            <span>生产信息登记</span>
          </div>
          <div class="body">
            <el-col :xs="24" :sm="24" :md="12" :lg="8">
              <div style="display:flex;align-items: center;justify-content: center;margin-bottom: 20px">
                <img
                  src="@/assets/images/saoyisao.png"
                  alt="donate"
                  width="100px"
                  @click="goUrl"
                />
              </div>
              <div style="display: flex;justify-content: center;color: #777;font-size: 13px">点击扫码</div>
            </el-col>
<!--            {{qcode}}-->
            <el-col :xs="24" :sm="24" :md="12" :lg="16">
            <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="120px">
              <el-col :lg="12">
                <el-form-item label="生产企业名称">
                  {{formData.manufacturer}}
                </el-form-item>
              </el-col>
              <el-col :lg="12">
                <el-form-item label="医院名称">
                  {{formData.hospitalName}}
                </el-form-item>
              </el-col>
              <el-col :lg="12">
                <el-form-item label="订单日期">
                  {{formData.orderDate}}
                </el-form-item>
              </el-col>
              <el-col :lg="12">
                <el-form-item label="药品名称">
                  {{formData.goodsname}}
                </el-form-item>
              </el-col>
              <el-col :lg="12">
                <el-form-item label="标示时间">
                  {{formData.ufFlagtime}}
                </el-form-item>
              </el-col>
              <el-col :lg="12">
                <el-form-item label="放射性活度">
                  {{formData.ufGoodsrat}}
                  <span style="margin-left: 10px">MBq</span>
                </el-form-item>
              </el-col>
              <el-col :lg="12">
                <el-form-item label="特殊要求">
                  {{ formData.specRequmts }}
                </el-form-item>
              </el-col>
              <el-col>
<!--                <el-col :lg="12">-->
<!--                  <el-form-item label="标示时间">-->
<!--                    <el-date-picker v-model="formData.ufFlagtime" format="yyyy-MM-dd HH:mm" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"-->
<!--                                    :default-time="'01:00:00'" :style="{width: '100%'}" placeholder="请选择标示时间" clearable></el-date-picker>-->
<!--                  </el-form-item>-->
<!--                </el-col>-->
<!--                <el-col :lg="12">-->
<!--                  <el-form-item label="放射性活度">-->
<!--                    <div style="display:flex;align-items: center">-->
<!--                      <el-input v-model="formData.ufGoodsrat" placeholder="请输入放射性活度值" ></el-input>-->
<!--                      <span style="margin-left: 10px">MBq</span>-->
<!--                    </div>-->
<!--                  </el-form-item>-->
<!--                </el-col>-->
                <el-col :lg="12">
                  <el-form-item label="数量">
                    <el-input v-model="formData.num" placeholder="请输入数量" ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :lg="12">
                  <el-form-item label="批号">
                    <el-input v-model="formData.batchcode" placeholder="请输入批号" ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :lg="12">
                  <el-form-item label="生产日期">
                    <el-date-picker v-model="formData.produceDate" format="yyyy-MM-dd HH:mm" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
                                    :default-time="'01:00:00'" :style="{width: '100%'}" placeholder="请选择生产日期" clearable></el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :lg="12">
                  <el-form-item label="有效期">
                    <el-date-picker v-model="formData.validDate" format="yyyy-MM-dd HH:mm" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
                                    :default-time="'01:00:00'" :style="{width: '100%'}" placeholder="请选择有效期" clearable></el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :lg="12">
                  <el-form-item label="发货人">
                    <el-input v-model="formData.shipper" placeholder="请输入发货人" ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :lg="12">
                  <el-form-item label="质检报告">
<!--                    <el-upload-->
<!--                      class="upload-demo"-->
<!--                      :action="field103Action"-->
<!--                      :before-upload="field103BeforeUpload"-->
<!--                      :before-remove="beforeRemove"-->
<!--                      :on-success="handle_success"-->
<!--                      :on-remove="handle_remove"-->
<!--                      multiple-->
<!--                      :limit="3"-->
<!--                      :on-exceed="handleExceed"-->
<!--                      :file-list="fileList">-->
<!--                      <el-button size="small" type="primary">点击上传</el-button>-->
<!--                    </el-upload>-->
                    <file-upload v-model="formData.qualityReport"/>
                  </el-form-item>
                </el-col>

                <el-col :lg="24">
                  <el-form-item size="large">
                    <el-button type="primary" style="float: right" @click="submitForm">提交</el-button>
                  </el-form-item>
                </el-col>
              </el-col>
            </el-form>
            </el-col>
          </div>

        </el-card>
      </el-col>
  </div>
</template>

<script>

import {getProduceAndTransInfo, getProduceAndTransInfoErp, updateZsdt, updateZsdtErp} from '@/api/flow/produceAndTrans'

export default {
  data(){
    return {
      loading:false,
      qcode:'',//二维码id
      //点击上传
      field103Action: process.env.VUE_APP_BASE_API + "/common/upload",
      field103fileList: [],
      fileList:[],

      erwm:'二维码数据',
      formData: {
        qualityReport:'',
        manufacturer:'',//生产企业名称
        hospitalName:'',//医院名称
        orderDate:'',//订单日期
        goodsname:'',//药品名称
        ufFlagtime:'',//标示时间
        ufGoodsrat:'',//放射性活度
        num:'',//数量
        specRequmts:'',//特殊要求
        batchcode: '',//批号
        produceDate: '',//生产日期
        validDate:'',//有效期
        shipper:'',//发货人
      },
      rules: {
        batchcode: [{
          required: true,
          message: '请输入批号',
          trigger: 'blur'
        }],
        // field103: [{
        //   required: true,
        //   message: '请输入单行文本',
        //   trigger: 'blur'
        // }],
      },
    }
  },
  created() {
    let querys= this.$route.query
    console.log('上级传参',querys)
    if(querys.qrresult){
      this.qcode=querys.qrresult
    }
    //根据二维码id获取信息
    this.getInfo()
  },
  methods:{
    //删除-同步删除fileList内的对应数据
    handle_remove(file, fileList) {
      var _tmp = this.fileList;
      for (var i = 0, len = _tmp.length; i < len; i++) {
        if (_tmp[i].name = file.name) {
          _tmp.splice(i, 1);
          break;
        }
      }
      this.fileList = _tmp;
    },
    //文件上传成功-同步增加fileList内的对应数据
    handle_success(response, file, fileList) {
      console.log('上传成功',response)
      console.log('上传成功2',file)
      console.log(URL.createObjectURL(file.raw));
      this.fileList.push({
        name: file.name,
        url: file.response.url
      });
    },
    handleExceed(files, fileList) {
      this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
    },
    //移除前弹窗确认
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${ file.name }？`);
    },
    //点击上传(文件)-上传时事件监听
    field103BeforeUpload(file) {
      console.log('点击上传',file)
      let isRightSize = file.size / 1024 / 1024 < 100
      if (!isRightSize) {
        this.$message.error('文件大小超过 100MB')
      }
      console.log('上传0',isRightSize)
      return isRightSize
    },
    //二维码功能跳转+扫码后返回路径设置
    goUrl(){
      window.location.href='//996315.com/api/scan/?redirect_uri='+window.location.origin+'/order/from/producefrom'
    },
    getInfo(){
      this.loading = true;
      getProduceAndTransInfoErp(this.qcode).then(res =>{
        if(res.code == 200 ){
          if(res.data.length > 0){
            console.log('二维码内容',res.data[0])
            this.formData = res.data[0];
            // if(this.formData.qualityReport){
            //   this.fileList=JSON.parse(this.formData.qualityReport)
            // }
          }
        }else {
          this.$message.error(res.msg)
        }
        this.loading = false;
      })
    },
    //提交
    submitForm(){
      this.loading = true;
      //获取当前用户的id，赋值update_by字段
      if(this.$store.state.user.userId){
        this.formData.updateBy = this.$store.state.user.userId;
      }
      //图片路径同步
      // this.formData.qualityReport=JSON.stringify(this.fileList)
      console.log('提交信息',this.formData)
      updateZsdtErp(this.formData).then(res =>{
        if(res.code == 200){
          this.$message.success('更新成功')
          this.reset()
        }else {
          this.$message.error(res.msg)
        }
        this.loading = false;
      })
    },
    //formData重置
    reset(){
      this.formData={
        amount:null,
        batchcode:null,
        bsdate:null,
        createTime:null,
        dedrate:null,
        driverInfo:null,
        endDatetime:null,
        execnum:null,
        goodid:null,
        goodscode:null,
        goodsname:null,
        goodsspec:null,
        hospitalName:null,
        hospitalShr:null,
        manufacturer:null,
        num:null,
        oldprice:null,
        orderId:null,
        piclink:null,
        place:null,
        price:null,
        produceDate:null,
        qcode:null,
        qualityReport:null,
        radioActivity:null,
        shipper:null,
        startDatetime:null,
        transportUnit:null,
        unit:null,
        validDate:null,
        vehicleInfo:null,
        ysSituation:null,
      }
    }

  }
}
</script>

<style>

</style>
